
package com.phevos.common.dbpool;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * �Զ���DAO��ȱʡ���ࡣ�̳в�ʵ����GenericDAO�Ĵ󲿷ַ�����Ϊ����������ṩ����
 * 
 * @author somebody
 */
public class DAOSupport extends GenericDAO
{

    /**
     * ���캯��
     * 
     * @param transMgr ���ڻ��һ�� DBConnection �Ķ���ʵ�� - * ���캯��
     * @param transMgr ���ڻ��һ�� DBConnection �Ķ���ʵ��
     * @throws java.sql.SQLException
     */
    public DAOSupport(Connection conn) throws SQLException
    {
        super(conn);
    }

    /**
     * ���캯��
     * 
     * @throws java.sql.SQLException
     */
    public DAOSupport()
    {
        super();
    }

    /**
     * You must implemetate the metod when you use doFind() method to get the ResultSet, otherWise
     * throw RuntimeException.
     * 
     * @param rs
     * @param flag
     * @param obj
     * @throws SQLException
     * @throws java.sql.SQLException
     */
    protected void extractFromFindResultSet(ResultSet rs, int flag, Object obj) throws SQLException
    {
        throw new RuntimeException("extractFromResultSet is not implemented");
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.union.center.common.GenericDAO#fillFindStatement(java.sql.PreparedStatement, int,
     *      java.lang.Object)
     */
    protected void fillFindStatement(PreparedStatement stmt, int flag, Object obj)
            throws SQLException
    {
        // TODO Auto-generated method stub

    }

    protected String getPageSql(String querySql, int pageSize, int pageNo)
    {
        String pageSql = "select * from ( select rownum as row_num,tb2.* from( select tb1.* from ";
        pageSql += "(" + querySql + ")";
        int startIndex = 1;
        if (pageNo != 1)
        {
            startIndex = pageSize * (pageNo - 1) + 1;
        }
        pageSql += "  tb1)tb2 ) where row_num>=" + startIndex;
        pageSql += " and row_num<=" + pageSize * pageNo;
        return pageSql;
    }

}
